<template>
  <div>
    <!-- 睿蓝经销商打款审核提交 -->
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
    >
      <template slot="controls" slot-scope="props">
        <el-button size="small" type="primary" icon="el-icon-plus" @click="add()">新增</el-button>
      </template>
    </FilterTable>

    <BaseDialog
      :visible.sync="openOrClosePaymentAuditAdd"
      :title="'打款审核新增'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <paymentAuditAdd @close="closeHandler" />
    </BaseDialog>
    
        <!-- 查看凭证 -->
    <el-image-viewer :url-list="imageList" v-show="imagesViewShow" :on-close="closeImagesViewer"></el-image-viewer>

  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { auditAdd,dealerRemitInfo,findFileByUrl} from '@/api/partsmanage/financialManagement/capitalAccount/index';
import paymentAuditAdd from '@/pages/partsmanage/financialManagement/dlrPaymentReview/customPopup/paymentAuditAdd';
import { notifyAction } from '@/utils';
import ElImageViewer from 'element-ui/packages/image/src/image-viewer';

export default {
  name: "dlrPaymentReview",
  mixins: [dictionary],
  components: {paymentAuditAdd,ElImageViewer},
  data() {
    return{
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: dealerRemitInfo,
      openOrClosePaymentAuditAdd: false,
      fetchParams: {xhrAbort: true},
      imageList:[],
      imagesViewShow:false
    };
  },
  methods: {
    closeImagesViewer() {
      this.imagesViewShow = false;
    },
    closeHandler(){//新增窗口关闭
      this.openOrClosePaymentAuditAdd = false;
      //刷新页面
      this.fetchParams = Object.assign({}, this.fetchParams);
    },
    add(row){//新增按钮
      
      this.openOrClosePaymentAuditAdd = true;
    },
    async commit(row){//提交按钮
      let data = row;
      data.mark = "commit";
      let result = await auditAdd(data);
      if (result.resultCode === 200) {
        this.$notify.success({title: '提示信息',message:'提交成功!'});
        this.loadingFlag2 = false;
        this.closeHandler();

      } else {
        this.$notify.error({title: '提示信息',message:result.errMsg||'提交失败!'});
      }

    },
    async invalid(row){//作废按钮
      let data = row;
      data.mark = "invalid";
      let result = await auditAdd(data);
      if (result.resultCode === 200) {
        this.$notify.success({title: '提示信息',message:'作废成功!'});
        this.loadingFlag2 = false;
        this.closeHandler();

      } else {
        this.$notify.error({title: '提示信息',message:result.errMsg||'作废失败!'});
      }
    },
    async look(row){//查看按钮
      if(row.uploadFile.length <= 0 || row.uploadFile[0].url == null || row.uploadFile[0].url == ''){
        return notifyAction('当前记录凭证为空!', 'warning');
      }
      this.imagesViewShow = true;
      this.imageList = [];
      findFileByUrl(row.uploadFile[0].url).then(res => {
        this.imageList.push(res.data);
      })
    },
    createTopFilterList() {
      return[
        {
          type: 'RANGE_DATE',
          label: '打款日期',
          fieldName: 'remitDate1|remitDate2',
          placeholder: '请选择...',
          valueFormat: 'yyyy-MM-dd'
        },
        {
          type: 'SELECT', 
          label: '状态', 
          fieldName: 'paymentStatus', 
          placeholder: '请选择',
          itemList: this.createDictList('3008')
        }
      ]
    },
    createTableColumns () {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          align:"center",
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          align:"center",
          render: (props, h) => {
            return (
              <div>
                <el-button disabled = {props.row.paymentStatus != 30081001} size="mini" type="text" onClick={() => this.commit(props.row)}>
                  提交
                </el-button>
                <el-button disabled = {props.row.paymentStatus != 30081001} size="mini" type="text" onClick={() => this.invalid(props.row)}>
                  作废
                </el-button>
              </div>
            );
          }
        },
        {
          title: '状态',
          dataIndex: 'paymentStatus',
          sorter: true,
          filter: true,
          dictItems: this.createDictList('3008')
        },
        {
          title: '审核意见',
          dataIndex: 'auditView',
          sorter: true,
          align:"center"
        },
        {
          title: '凭证查看',
          dataIndex: 'column-action',
          width: 100,
          align:"center",
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.look(props.row)}>
                  查看
                </el-button>
              </div>
            );
          }
        },
        {
          title: '票号',
          dataIndex: 'paymentNo',
          sorter: true,
          align:"center"
        },
        {
          title: '收款银行',
          dataIndex: 'bank',
          sorter: true,
          align:"center"
        },
        {
          title: '打款人',
          dataIndex: 'paymentPerson',
          sorter: true,
          align:"center"
        },
        {
          title: '打款金额',
          dataIndex: 'amount',
          sorter: true,
          precision: 2,
          align:"center"
        },
        {
          title: '打款日期',
          dataIndex: 'remitDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat:'yyyy-MM-dd'
        },
        {
          title: '款项类型',
          dataIndex: 'paymentType',
          sorter: true,
          filter: true,
          dictItems: this.createDictList('3007')
        },
        {
          title: '提交日期',
          dataIndex: 'updatedAt',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat:'yyyy-MM-dd'
        },
        {
          title: '提交人',
          dataIndex: 'createdName',
          sorter: true,
          align:"center"
        },
        {
          title: '审核人',
          dataIndex: 'auditName',
          sorter: true,
          align:"center"
        },
        {
          title: '审核日期',
          dataIndex: 'auditDate',
          sorter: true,
          filter: true,
          filterType: 'date-range',
          dateFormat:'yyyy-MM-dd'
        }
      ]
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
  }
}
</script>